import { requestDetailInfo } from "@/api"

const state = {
  detailInfo: {}
}

const mutations = {
  SET_DETAILINFO_STATE(state, value) {
    state.detailInfo = value
  }
}

const actions = {
  async getDetailInfo({ commit }, skuId) {
    const result = await requestDetailInfo(skuId)
    commit("SET_DETAILINFO_STATE", result)
  }
}

const getters = {
  categoryView(state) {
    return state.detailInfo.categoryView || {}
  },
  spuSaleAttrList(state) {
    return state.detailInfo.spuSaleAttrList || []
  },
  skuInfo(state) {
    return state.detailInfo.skuInfo || {}
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}